package io.iec.edp.caf.caching.mock;

import io.iec.edp.caf.caching.api.Cache;
import io.iec.edp.caf.caching.api.CacheManager;
import io.iec.edp.caf.commons.utils.SpringBeanUtils;

/**
 * 订单服务：模拟业务场景，调用缓存组件添加订单，获取订单，删除订单
 *
 * @author manwenxing01
 */
public class OrderService {

    //缓存管理类
    private CacheManager manager;

    //add
    public void add(String name, Object order) {
        Cache cache = getCache();
        cache.put(name, order);
    }

    //the other addU
    public void addU(String name, Object order) {
        Cache cache = getCacheU();
        cache.put(name, order);
    }

    //get
    public Object get(String name) {
        Cache cache = getCache();
        return cache.get(name);
    }

    //get
    public <T> T get(String name, Class<T> clazz) {
        Cache cache = getCache();
        return cache.get(name, clazz);
    }

    //delete
    public void delete(String name) {
        Cache cache = getCache();
        cache.evict(name);
    }

    private Cache getCache() {
        return this.manager.getCache("CacheMock");
    }

    private Cache getCacheU() {
        CacheManager cacheManager = (CacheManager) SpringBeanUtils.getBean("CacheManager");
        return cacheManager.getCache("CacheMock");
    }

}
